package com.ruoyi.buildings.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.buildings.domain.SysBuildings;
import com.ruoyi.buildings.service.ISysBuildingsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 楼栋表Controller
 * 
 * @author ruoyi
 * @date 2022-10-14
 */
@RestController
@RequestMapping("/buildings/buildings")
public class SysBuildingsController extends BaseController
{
    @Autowired
    private ISysBuildingsService sysBuildingsService;

    /**
     * 查询楼栋表列表
     */
    @PreAuthorize("@ss.hasPermi('buildings:buildings:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBuildings sysBuildings)
    {
        startPage();
        List<SysBuildings> list = sysBuildingsService.selectSysBuildingsList(sysBuildings);
        return getDataTable(list);
    }

    /**
     * 导出楼栋表列表
     */
    @PreAuthorize("@ss.hasPermi('buildings:buildings:export')")
    @Log(title = "楼栋表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBuildings sysBuildings)
    {
        List<SysBuildings> list = sysBuildingsService.selectSysBuildingsList(sysBuildings);
        ExcelUtil<SysBuildings> util = new ExcelUtil<SysBuildings>(SysBuildings.class);
        util.exportExcel(response, list, "楼栋表数据");
    }

    /**
     * 获取楼栋表详细信息
     */
    @PreAuthorize("@ss.hasPermi('buildings:buildings:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(sysBuildingsService.selectSysBuildingsById(id));
    }

    /**
     * 新增楼栋表
     */
    @PreAuthorize("@ss.hasPermi('buildings:buildings:add')")
    @Log(title = "楼栋表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBuildings sysBuildings)
    {
        return toAjax(sysBuildingsService.insertSysBuildings(sysBuildings));
    }

    /**
     * 修改楼栋表
     */
    @PreAuthorize("@ss.hasPermi('buildings:buildings:edit')")
    @Log(title = "楼栋表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBuildings sysBuildings)
    {
        return toAjax(sysBuildingsService.updateSysBuildings(sysBuildings));
    }

    /**
     * 删除楼栋表
     */
    @PreAuthorize("@ss.hasPermi('buildings:buildings:remove')")
    @Log(title = "楼栋表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(sysBuildingsService.deleteSysBuildingsByIds(ids));
    }
}
